<div class="layuimini-main">
	<div class="layui-form layuimini-form">
		<div class="layui-form-item">
			<label class="layui-form-label required">角色名称</label>
			<div class="layui-input-block">
				<input type="text" name="name" lay-verify="required" lay-reqtext="角色名不能为空" placeholder="请输入角色名" value="" class="layui-input">
				<tip>填写角色的名称。</tip>
			</div>
		</div>
		<div class="layui-form-item layui-form-text">
			<label class="layui-form-label">备注信息</label>
			<div class="layui-input-block">
				<textarea name="remark" class="layui-textarea" placeholder="请输入备注信息"></textarea>
			</div>
		</div>

		<div class="layui-form-item">
			<div class="layui-input-block">
				<button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
			</div>
		</div>
	</div>
</div>
<script>
	layui.use(['form', 'table', 'hsw'], function() {
		var form = layui.form,
			layer = layui.layer,
			table = layui.table,
			hsw = layui.hsw,
			$ = layui.$;
		
		// 当前弹出层，防止ID被覆盖
		var parentIndex = layer.index;

		//监听提交
		form.on('submit(saveBtn)', function(data) {
			
			hsw.hsw_post(HSW_API_MANAGE_ROLE_ADD, data.field, function(data) {

					layer.msg('操作成功，即将刷新页面', {
						time: 3000 //
					}, function() {
						hsw.hsw_html_reload(0);
					});

					// 关闭弹出层
					layer.close(index);
					layer.close(parentIndex);

			});
			return false;
		});
		
		window.editInit = function(data){
			
			$('input[name="pid"]').attr('value',data.pid);
			$('input[name="name"]').attr('value',data.name);
			$('input[name="code"]').attr('value',data.code);
			$('textarea[name="remark"]').val(data.remark);
			
			form.render();
			
		}
	});
</script>
